<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" trimDirectiveWhitespaces="true"%>
<%@ page import="java.util.Date"%>
<%@ include file="../security/include.inc.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title>User</title>
<style type="text/css">
.New_Button,.Edit_Button,.Delete_Button,.Update_Button,.Cancel_Button {
	font-size: 11px;
	color: #1B3F91;
	font-family: Verdana;
	margin-right: 5px;
}
</style>
</head>
<body>
	<div class="mini-splitter" style="width: 100%; height: 100%;">
		<div size="350" showCollapseButton="true">
			<div class="mini-toolbar"
				style="padding: 2px; border-top: 0; border-left: 0; border-right: 0;">
				<span style="padding-left: 5px;">名称：</span> <input
					class="mini-textbox" /> <a class="mini-button"
					iconCls="icon-search" plain="true">查找</a>
			</div>
			<div id="datagrid1" class="mini-datagrid" style="width: 700px; height: 95%;"  fitColumns="false"
	allowResize="true" sizeList="[20,30,50,100]" pageSize="20" url="<%=basePath%>/levelMaster/list">
				<div property="columns">
					<div type="indexcolumn"></div> 
					<div field="level_id" width="100" headerAlign="center" allowSort="true">等级编号</div>
					<div field="level_name" width="100" headerAlign="center" allowSort="true">等级名称</div>
					<div field="level_fee" width="100" headerAlign="center" allowSort="true">缴费金额</div>
				</div>
			</div>
		</div>
		<div>
			<div class="mini-toolbar" style="padding: 2px; border-top: 0; border-left: 0; border-right: 0;">
				<a class="mini-button" iconCls="icon-add" onclick="add()">增加</a>
				<span class="separator"></span>
                <a class="mini-button" iconCls="icon-add" onclick="edit()">编辑</a>
                <span class="separator"></span>
                <a class="mini-button" iconCls="icon-remove" onclick="remove()">删除</a> 
                <span class="separator"></span>
                <a class="mini-button" iconCls="icon-save" plain="true" onclick="saveData()">保存</a>   
			</div>
			<div class="mini-fit" style="padding-left: 50px">
				<!-- 基本信息 -->
				<fieldset id="fd1" style="width: 650px;">
					<legend>
						<span>等级信息</span>
					</legend>
					<input name="state" class="mini-hidden" />
					<table style="width: 100%;">
						<tr>
							<td style="width: 80px;">等级编号：</td>
							<td style="width: 150px;"><input name="level_id"
								class="mini-textbox" /></td>
							<td style="width: 80px;">等级名称：</td>
							<td style="width: 150px;"><input name="level_name"
								class="mini-textbox" /></td>
						</tr>
						<tr>
							<td style="width: 80px;">缴费金额：</td>
							<td style="width: 150px;"><input name="level_fee"
								class="mini-textbox"></input></td>
							<td style="width: 80px;">等级排序：</td>
							<td style="width: 150px;">
							<input name="level_order"
								class="mini-textbox"></input>
							</td>
						</tr>
					</table>
				</fieldset>
				<div id="userTabs" class="mini-tabs" activeIndex="0" style="width:90%;height:300px;padding-top:40px" plain="false">
					<div title="权限关联" >
					</div>
			</div>
			</div>
			
			
		</div>
	</div>
	
	<script type="text/javascript">
	 	mini.parse();
		var grid = mini.get("datagrid1");
		var userRoleGrid = mini.get("datagrid2");
	    grid.load();
	    
	    var form = new mini.Form("fd1");
	    
	    readonlyModel(form);
	    
	    
	    
		//////////////////////////////////////////////////////
		
		//加载菜单信息
		grid.on('rowclick',function(e){
			readonlyModel(form);
			form.setData(e.row);
		});
		
		function add(){
			editModel(form,'added');
		}
		
		function edit(){
			editModel(form,'modified',function(field){
	 			if(field.name == 'level_id'){
	 				if (field.setReadOnly) field.setReadOnly(true);     //只读
		            if (field.addCls) field.addCls("asLabel");          //增加asLabel外观
	 			}
	 		});	
		}
		
		function saveData(){
			var data = form.getData();
			
			console.log(data);	
			
			var json = mini.encode([data]);
            $.ajax({
                url: "<%=basePath%>/levelMaster/save",
                data: { data: json },
                success: function (text) {
                	alert(text);
                	grid.reload();
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                }
            });
		}
		
		function updateRow() {            
            var form = new mini.Form("#editform");
            var o = form.getData();

            grid.loading("保存中，请稍后......");
            var json = mini.encode([o]);
            $.ajax({
                url: "<%=basePath%>/levelMaster/save",
                data: { data: json },
                success: function (text) {
                	alert(text);
                    grid.reload();
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                }
            });

             
        }
		 
        function search() {       
            var key = mini.get("key").getValue();
            grid.load({ code_name : key });
        }
        function onKeyEnter(e) {
            search();
        }
        
	</script>
</body>
</html>